﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for SlideShowDAO
/// </summary>
public class SlideShowDAO
{
    DataProvider provider;
	public SlideShowDAO()
	{
        provider = new DataProvider();
	}

    public List<SlideShow> HienThiSlideShow()
    {
        List<SlideShow> list = new List<SlideShow>();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_HienThiSlideShow", provider.Conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection.Open();

            SqlDataAdapter adapter = new SqlDataAdapter();
            DataSet ds = new DataSet();
            adapter.SelectCommand = cmd;
            adapter.Fill(ds);
            provider.Conn.Close();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                SlideShow dto = new SlideShow();
                dto.IDHinh = Convert.ToInt32(ds.Tables[0].Rows[i]["IDHinh"].ToString());
                dto.TenHinh = ds.Tables[0].Rows[i]["TenHinh"].ToString();
                dto.HienThi = Convert.ToInt32(ds.Tables[0].Rows[i]["HienThi"].ToString());
                dto.ChuThich = ds.Tables[0].Rows[i]["ChuThich"].ToString();
                list.Add(dto);
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            provider.Conn.Close();
        }
        return list;
    }

    public SlideShow HienThiChiTietSlideShow(int idSlideShow)
    {
        SlideShow dto = new SlideShow();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_HienThiChiTietSlideShow", provider.Conn);
            cmd.Parameters.Add("@ID", SqlDbType.Int).Value = idSlideShow;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection.Open();

            SqlDataAdapter adapter = new SqlDataAdapter();
            DataSet ds = new DataSet();
            adapter.SelectCommand = cmd;
            adapter.Fill(ds);
            provider.Conn.Close();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dto.IDHinh = Convert.ToInt32(ds.Tables[0].Rows[i]["IDHinh"].ToString());
                dto.TenHinh = ds.Tables[0].Rows[i]["TenHinh"].ToString();
                dto.HienThi = Convert.ToInt32(ds.Tables[0].Rows[i]["HienThi"].ToString());
                dto.ChuThich = ds.Tables[0].Rows[i]["ChuThich"].ToString();
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            provider.Conn.Close();
        }
        return dto;
    }
}